package com.dragon.backstage.domain.param.role;

import com.dragon.common.utils.AjaxResult;
import com.dragon.interfaces.constant.RoleConstant;
import com.google.common.collect.Lists;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import java.util.List;
import java.util.Objects;

/**
 * 角色模块-添加角色请求参数
 *
 * @author dragon
 * @version 1.0
 * @date 2024/8/7 17:06
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Schema(title = "角色模块-添加角色请求参数")
public class RoleAddParam {

    /**
     * 角色名称
     */
    @Schema(title = "角色名称", requiredMode = Schema.RequiredMode.REQUIRED)
    private String roleName;

    /**
     * 权限字符
     */
    @Schema(title = "权限字符", requiredMode = Schema.RequiredMode.REQUIRED)
    private String roleKey;

    /**
     * 显示顺序
     */
    @Schema(title = "显示顺序", requiredMode = Schema.RequiredMode.REQUIRED)
    private Integer roleSort;

    /**
     * 角色状态（1正常 0禁用）
     */
    @Builder.Default
    @Schema(title = "角色状态（1正常 0禁用）", requiredMode = Schema.RequiredMode.REQUIRED)
    private Byte status = 1;

    /**
     * 备注
     */
    @Schema(title = "备注")
    private String remark;

    /**
     * 菜单ID列表
     */
    @Schema(title = "菜单ID列表")
    private List<Long> menuIds;


    /**
     * 添加角色请求参数校验
     */
    public static AjaxResult<Void> check(RoleAddParam param) {
        // 菜单状态枚举值
        List<Byte> statusArr = Lists.newArrayList(
            RoleConstant.STATUS_NORMAL,
            RoleConstant.STATUS_DISABLED
        );
        if (Objects.isNull(param)) {
            return AjaxResult.failed("请求参数不能为空");
        }
        if (StringUtils.isBlank(param.getRoleName())) {
            return AjaxResult.failed("角色名称不能为空");
        }
        if (StringUtils.isBlank(param.getRoleKey())) {
            return AjaxResult.failed("权限字符不能为空");
        }
        if (Objects.isNull(param.getRoleSort())) {
            return AjaxResult.failed("显示顺序不能为空");
        }
        if (Objects.isNull(param.getStatus())) {
            return AjaxResult.failed("状态不能为空");
        }
        if (!statusArr.contains(param.getStatus())) {
            return AjaxResult.failed("状态的值不符");
        }

        return AjaxResult.succeed();
    }

}
